﻿using System;
using System.IO;

using System.Web.Hosting;

namespace SBPweb.Services.Base
{

    public class VirtualServiceFile : VirtualFile
    {

        private ServiceBase pSvcBase;

        public VirtualServiceFile(string virtualPath, ServiceBase serviceBase)
            : base(virtualPath)
        {
            pSvcBase = serviceBase;
        }

        public override bool IsDirectory
        {
            get
            {
                return false;
            }
        }

        public override Stream Open()
        {
            Type type = pSvcBase.GetType();
            string s = string.Format("<%@ WebService Language=\"C#\" Class=\"{0}\" %>", type.AssemblyQualifiedName);
            MemoryStream stream = new MemoryStream();
            stream.Write(System.Text.Encoding.ASCII.GetBytes(s), 0, s.Length);
            stream.Flush();
            stream.Position = 0;
            stream.Seek(0, SeekOrigin.Begin);
            return stream;
        }

    }

}